#ifndef __FILE__ROW__
#define  __FILE__ROW__

#include<iostream>
#include "log.hpp"
#include<errno.h>
#include<cstring>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>

using namespace std;

#define SIZEM 4096

const char* pathname="/home/tao";
int proj_id=999;

Log log;

key_t GetKey(){
    key_t key=ftok(pathname,proj_id);
    if(key==-1){
        log(Fatal,"ftok errno:%d strerror:%s",errno,strerror(errno));
        exit(2);
    }
    log(Info,"ftok success key is 0x%x",key);
    return key;
}

int GetShareMemHelp(int flag){
    key_t key=GetKey();
    int shmid=shmget(key,SIZEM,flag);
    if(shmid==-1){
        log(Fatal,"shmget fail:strerror:%s",strerror(errno));
        exit(2);
    }
    log(Info,"ftok success shmid 0x%d",shmid);
    return shmid;
}
 
int GetShare(){
    return GetShareMemHelp(IPC_CREAT);
}

int CreatShare(){
    return GetShareMemHelp(IPC_CREAT|IPC_EXCL|0666);
}







#endif